%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[10pt, fleqn]{article}
\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{lastpage}
\usepackage{multicol}

% DOCUMENT LAYOUT
\usepackage{geometry} 
\geometry{letterpaper, textwidth=6.5in, textheight=9in}
\setlength{\parindent}{0in}

% SECTION HEADINGS
\usepackage{sectsty}
\sectionfont{\mdseries}

% ITEM ENVIRONMENT
\newenvironment{baseenumerate}
  {\begin{enumerate}[leftmargin=0pt]
	\setlength{\baselineskip}{0pt}
	\setlength{\itemsep}{0pt}
	\setlength{\parskip}{10pt}}
  {\end{enumerate}}
	
\newenvironment{myenumerate}
  {\begin{enumerate}[leftmargin=*]
	\setlength{\baselineskip}{0pt}
    \setlength{\itemsep}{0pt}
	\setlength{\parskip}{10pt}}
  {\end{enumerate}}

\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\labelenumii}{(\alph{enumii})}
\renewcommand{\labelenumiii}{\roman{enumiii}.}

% PAGE NUMBERS
\usepackage{fancyhdr}
\pagestyle{fancy}
\cfoot{}
\rfoot{\textbf{\thepage} / \pageref{LastPage}}
\renewcommand{\headrulewidth}{0pt}

% DOCUMENT
\begin{document}

\begin{multicols}{2}
  \textbf{Assignment 1.}
  \columnbreak
  
  \begin{flushright}
	Benedict Yip \\
	February 15, 2011 \\
	CS 378
  \end{flushright}
\end{multicols}

\begin{flushleft}
  
  \begin{baseenumerate}

  \item % 1.
    \begin{myenumerate}

    \item % a)
      $ \left[\begin{smallmatrix} x_{i+1} \\ y_{i+1} \end{smallmatrix}\right]
      = \left[\begin{smallmatrix} 1/3 & 0 \\ 0 & 1/2 \end{smallmatrix}\right]
      \left(
      \left[\begin{smallmatrix} -1 \\ 3 \end{smallmatrix}\right] - 
      \left[\begin{smallmatrix} 0 & -4 \\ 1 & 0 \end{smallmatrix}\right]
      \left[\begin{smallmatrix} x_i    \\ y_i \end{smallmatrix}\right]
      \right) $
      
    \item % b)
      As k (the iteration number) increases, the approximation $(x_k, y_k)$ converges to the real solution. \\
      \includegraphics[scale=0.6]{1b.png}
      
    \item % c)
      For $n=27$ (the number of iterations), relative error is $(0.0017, 0.0077) < (0.01, 0.01)$.

    \item % d)
      \begin{myenumerate}

        \item % i.
          $ \left[\begin{smallmatrix} x_{i+1} \\ y_{i+1} \end{smallmatrix}\right]
          = \left[\begin{smallmatrix} 1/3 & 0 \\ -1/6 & 1/2 \end{smallmatrix}\right]
          \left(
          \left[\begin{smallmatrix} -1 \\ 3 \end{smallmatrix}\right] - 
          \left[\begin{smallmatrix} 0 & -4 \\ 0 & 0 \end{smallmatrix}\right]
          \left[\begin{smallmatrix} x_i    \\ y_i \end{smallmatrix}\right]
          \right) $

        \item % ii.
          As k (the iteration number) increases, the approximation $(x_k, y_k)$ converges to the real solution. \\
          \includegraphics[scale=0.6]{1d.png}

        \item % iii.
          For $n=16$ (the number of iterations), relative error is $(0.0076, 0.0038) < (0.01, 0.01)$.

      \end{myenumerate}

    \end{myenumerate}
    
  \item % 2.
    \begin{myenumerate}
      
    \item % a)
      The equation $\frac{d^2y}{dx^2} = -y$ can be written as $y'' + y = 0$. This gives us the auxiliary equation $r^2 + 1 = 0$. The roots of this equation are given by inspection: $r = \pm i$. Because the auxiliary equation has complex roots, we know that the solution takes the general form of $y = e^{\alpha x}\left( c_1 \cos \beta x + c_2 \sin \beta x \right)$, where $\alpha$ and $\beta$ are given by the roots of the form $r = \alpha \pm \beta i$.
      
      Thus, we have $y = c_1 \cos x + c_2 \sin x$.
      
      From the initial conditions, we see the following:
      \begin{align*}
        y(0) = 0 &= c_1 \cos 0 + c_2 \sin 0 \\
        &= c_1
      \end{align*}
      
      and
      \begin{align*}
        y'(0) = 1 &= c_2 \cos 0 \\
        &= c_2.
      \end{align*}
      
      Given these constants, we have $y = \sin x$.

    \item % b)
      For $N = 10$, $y_{approx}(10 * pi) = -0.0006$. For $N = 100$, $y_{approx}(10 * pi) = -0.0115$. At $N = 7$, $y_{approx}$ is within $1\%$ of $y_{exact}$.
      
    \end{myenumerate}
    
  \item % 3.
    For $N = 10$, $y_{approx}(10 * pi) = 1.0584 \cdot 10^8$. For $N = 100$, $y_{approx}(10 * pi) = -0.2153$. At $N = 3101$, $y_{approx}$ is within $1\%$ of $y_{exact}$.
    
  \item % 4.
	\begin{myenumerate}

      \item % a)
        Yes, as time progresses, the entirety of the metal rod matches the temperature of the ends. \\
        \includegraphics[scale=0.6]{4a.png}

      \item % b)

        Because the time step is too large, the method becomes unstable. \\
        \includegraphics[scale=0.6]{4b.png}

    \end{myenumerate}
    
  \item % 5.
    No, the instability that shows up for the Forward-Euler discretization does not show up when using the Crank-Nicolson scheme.
	\begin{myenumerate}

      \item % a)
        With dt = 0.025: \\
        \includegraphics[scale=0.6]{5a.png}

      \item % b)
        With dt = 0.05: \\
        \includegraphics[scale=0.6]{5b.png}

    \end{myenumerate}

  \item % 6.
    (Included as parameterProfile.pdf.)
    
%  \item % 7.
%	This claim is true. We show the following proof:
%	\begin{myenumerate}
%	\item % i.
%	  $L \in D$ by definition.
%	  
%	\item % ii.
%	  We prove this by construction. Because $D$ is closed under complement, we know that $\exists M, M'$, Turing machines, that decide $L, \lnot L$ respectively. Assuming a lexicographical enumeration of $\Sigma^{*}$ of $s_{1}, s_{2}, \dots$, we have that $w' \in L'$ iff $F(w') \in L$, with
%	  
%	  \begin{tabular}{lll}
%		\multicolumn{3}{l}{F(w) =} \\
%		1.   & \multicolumn{2}{l}{For $i = 1 \to \infty:$} \\
%		& 1.1. & Run w' on N' and $s_{i}$ on N. \\
%		& 1.2.	& If both machines accept/reject, return $s_{i}$. \\
%	  \end{tabular}
%	  
%	\end{myenumerate}
	
  \end{baseenumerate}
\end{flushleft}

\end{document}
